<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%@ page import="projects.project" %>
<%@ page import="projects.milestone" %>
<%@ page import="java.util.ArrayList"%>
<%@ page import="java.util.Hashtable"%>
<%@ page import="java.util.Enumeration"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<jsp:useBean id="project" class="projects.project"></jsp:useBean>
<jsp:setProperty property="*" name="project"/>
<jsp:useBean id="milestone" class="projects.milestone"></jsp:useBean>
<jsp:setProperty property="*" name="milestone"/>
<html>
<% 
if (session.getAttribute("loggedIn") == null) {
	response.sendRedirect("../User/index.jsp");
	}
else{
	project prj = new project();
	milestone mil = new milestone();
	prj.setProjectId(Integer.parseInt(request.getParameter("id")));
	mil.setProjectId(Integer.parseInt(request.getParameter("id")));
	ArrayList<String> prjInfo = prj.queryProjectInfo(); 
	Hashtable<Integer, ArrayList<String>> teamInformation = prj.queryProjectTeam();
	Hashtable<Integer, ArrayList<String>> milestoneInformation = mil.queryMilestonesByProjectId();
	Hashtable<Integer, ArrayList<String>> inProgressTasks = prj.returnNumberOfTasks();
%>
<%
ArrayList<Integer> completed = new ArrayList<Integer>();
ArrayList<Integer> total = new ArrayList<Integer>();

Enumeration<Integer> taskKeysEnum = inProgressTasks.keys();
ArrayList<Integer> taskKeys = new ArrayList<Integer>();
while(taskKeysEnum.hasMoreElements()){
	taskKeys.add(taskKeysEnum.nextElement());
}
for(Integer key : taskKeys) {
	
	ArrayList<String> inProgressTsk = new ArrayList<String>();
	inProgressTsk = inProgressTasks.get(key);
	if(Integer.parseInt(inProgressTsk.get(3).toString()) == 4){
		completed.add(key);
	}
	else{
		total.add(key);
	}}
	Integer totalTasks = total.size() + completed.size();
%>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link rel="stylesheet" type="text/css" href="../General Info/css.css" />
<title>Project Dashboard</title>
<script src="../General Info/amcharts.js" type="text/javascript"></script>
<script src="../General Info/raphael.js" type="text/javascript"></script>        
	    
        <script type="text/javascript">
		var open = <%out.println(total.size()); %>;
		var completed = <%out.println(completed.size()); %>
		var topen = 0;
		var tcomp = 1;
        var chart;
		var legend;
        var chartData = [{country:"Completed Tasks",litres:completed, color:"#9CBF1B"},
				{country:"Open Tasks",litres:open, color:"#FF0F00"}];

         window.onload = function() {
            chart = new AmCharts.AmPieChart();
            chart.dataProvider = chartData;
            chart.titleField = "country";
			chart.valueField = "litres";
			chart.colorField = "color";

			legend = new AmCharts.AmLegend();
			legend.align = "center";
			chart.addLegend(legend);

			chart.write("chartdiv");
		}
	    </script>
</head>

<body>
<jsp:include page="../General Info/header.jsp"/>

<%/* <!-- -----------------------------------------------> Submeniu <-------------------------------------------------- --> */%>
	<div class="submenu">
		<ul class="submenuBar">
			<%
			String projectLink = "../Milestones/createNewMilestone.jsp?id="+ (request.getParameter("id"));
			%>
			<li><a href=<% out.println(projectLink); %> class="submenuButton">Add Work Package</a></li>
		</ul>
	</div>
	
<% /* ------------------------------------------------------------------------------------------------------------------------------- */ %>

<div class="body">
	<div class="dashboard">
		<div class="up">
			<div class = "projects">
			<div class = "projectsHeader">Project Information</div>
			
			<table style="float: right">
					<tr>
						<td class="labelName">Project Name:</td>
						<td class="labelValue"><% out.println(prjInfo.get(1)); %></td>
					</tr>
					<tr>
						<td class="labelName">Project Code:</td>
						<td class="labelValue"><% out.println(prjInfo.get(5)); %></td>
					</tr>
					<tr>
						<td class="labelName">Project Description:</td>
						<td class="labelValue"><%out.println(prjInfo.get(2)); %></td>
					</tr>
					<tr>
						<td class="labelName">Start date:</td>
						<td class="labelValue"><%out.println(prjInfo.get(3)); %></td>
					</tr>
					<tr>
						<td class="labelName">End date:</td>
						<td class="labelValue"><%out.println(prjInfo.get(4)); %></td>
					</tr>
					<tr>
						<td class="labelName">Project effort:</td>
						<td class="labelValue"><%out.println(prjInfo.get(6)); %></td>
					</tr>
					<tr>
						<td class="labelName">Project State Name:</td>
						<td class="labelValue"><%out.println(prjInfo.get(7)); %></td>
					</tr>
					<tr>
						<td class="labelName">Project State Reason:</td>
						<td class="labelValue"><%out.println(prjInfo.get(8)); %></td>
					</tr>
					<tr>
						<td class="labelName">Project estimated cost:</td>
						<td class="labelValue"><%out.println(prjInfo.get(9)); %></td>
					</tr>
					<tr>
						<td class="labelName">For client:</td>
						<td class="labelValue"><%out.println(prjInfo.get(10)); %></td>
					</tr>
				</table>
		</div>
		
		<div class = "activity">
			<div class = "projectsHeader">Monitoring</div>
			<div id="chartdiv" style="width:100%; height:300px"></div>
		</div>
		</div>
		
		<div class="down">
		<div class = "upcomingActivities">
			<div class = "projectsHeader">Work Packages</div>
			<table style="float: right">
			<tr>
				<td></td>
				<td class="projectTableHeader">Milestone Number</td>
				<td class="projectTableHeader">Milestone Name</td>
				<td class="projectTableHeader">Days till deadline:</td>
				<td class="projectTableHeader">Status</td>
			</tr>
		<%
		Enumeration<Integer> milKeysEnum = milestoneInformation.keys();
		ArrayList<Integer> milKeys = new ArrayList<Integer>();
		while(milKeysEnum.hasMoreElements()){
			milKeys.add(milKeysEnum.nextElement());
		}
		int colorStyle = 0;
		for(Integer key : milKeys) {
			colorStyle = colorStyle + 1;
			ArrayList<String> milestones = new ArrayList<String>();
			milestones = milestoneInformation.get(key);
			String milestonePageLink = "../Milestones/milestone.jsp?id=" + key;   /* link + taskId */ 
		if(colorStyle %2 == 0){
		%>		
			<tr class="even">
				<td class="cell"></td>
				<td class="cell"><a href="<% out.println(milestonePageLink); %>"> <% out.println(key); %></a></td>   
				<td class="cell"><% out.println(milestones.get(0)); %></td>
				<td class="cell"><% out.println(milestones.get(2)); %></td>
				<td class="cell"><% out.println(milestones.get(1)); %></td>
			</tr>	

	<% }
		else{
			%>
			<tr class="odd">
				<td class="cell"></td>
				<td class="cell"><a href="<% out.println(milestonePageLink); %>"> <% out.println(key); %></a></td>   
				<td class="cell"><% out.println(milestones.get(0)); %></td>
				<td class="cell"><% out.println(milestones.get(2)); %></td>
				<td class="cell"><% out.println(milestones.get(1)); %></td>
			</tr>
		<%}
	}%>
			</table>
		</div>
		
		<div class="administration">
			<div class = "projectsHeader">Administration</div>
			
			<table style="float: right">
					<tr>
						<td></td>
						<td class="projectTableHeader">Employee</td>
						<td class="projectTableHeader">Role</td>
					</tr>
					<%
					Enumeration<Integer> teamInfoKeysEnum = teamInformation.keys();
					ArrayList<Integer> teamKeys = new ArrayList<Integer>();
					while(teamInfoKeysEnum.hasMoreElements()){
						teamKeys.add(teamInfoKeysEnum.nextElement());
					}
					int color = 0;
					for(Integer key : teamKeys) {
						color = color + 1;
						ArrayList<String> teamInfo = new ArrayList<String>();
						teamInfo = teamInformation.get(key);
						if(color %2 == 0){
						%>
						<tr class="even">
							<td class="cell"></td>
							<td class="cell"><% out.println(teamInfo.get(0)); %></td>   
							<td class="cell"><% out.println(teamInfo.get(1)); %></td>
						</tr>
						<%} 
						else{
							%>
						<tr class="odd">
							<td class="cell"></td>
							<td class="cell"><% out.println(teamInfo.get(0)); %></td>   
							<td class="cell"><% out.println(teamInfo.get(1)); %></td>
						</tr>
							<%
						}
						}%>	
				</table>
		</div>
		
		</div>
	</div>
	<div class="push"></div>
	</div>
	<jsp:include page="../General Info/footer.jsp"/>
</body>
<%} %>
</html>